﻿/**
 *	html/common/form_field.js
 *
 *	(C) 2014 Yuanjj
 *
 * 	history:
 * 		2014-07-19		create the file
 */

/**
 *	init plugins
 */
function init_plugins()
{
    _create_edit_plugin();
}

/**
 *	create edit plugin
 */
var g_edit_plugin;
function _create_edit_plugin()
{
    g_edit_plugin = new Ext.grid.plugin.CellEditing
    ({
         clicksToEdit:1
    });
}

/**
 *	create form field textarea
 *
 *	@parent			[in] the parent component object
 *	@label			[in] the lable name
 *	@lwidth			[in] the label width
 *	@width			[in] the component width
 *
 *	return
 *		the textarea component object
 */
function create_form_field_textarea( parent, label, lwidth, width )
{
    var textarea = new Ext.form.field.TextArea
    ({
         fieldLabel:label,
         labelWidth:lwidth,
         width:width
    });

    textarea.parent = parent;

    return textarea;
}

/**
 *	create button
 *
 *	@parent			[in] the parent component object
 *	@text			[in] the button text
 *	@handler		[in] the button handler
 *
 *	return
 *		the button object
 */
function create_form_field_button( parent, text, handler )
{
    var button = new Ext.button.Button
    ({
         text:text,
         handler:handler
    });

    button.parent = parent;

    return button;
}

/**
 *	create a combobox component
 *
 *	@parent			[in] the parent component object
 *	@label			[in] the lable name
 *	@lwidth			[in] the label width
 *	@width			[in] the component width
 *	@store			[in] the component store
 *	@disfield		[in] the display field
 *	@qmode			[in] the query mode ( rmote or local )
 *	@mh				[in] max height
 *	@vfield			[in] the value field
 *	@value			[in] the current value
 *
 *	return
 *		the combobox component object
 */
function create_form_field_combobox( parent, label, lwidth, width, store, disfield, qmode, mh, vfield, value )
{
    var combox = new Ext.form.field.ComboBox
    ({
         fieldLabel:label,
         labelWidth:lwidth,
         width:width,
         store:store,
         displayField:disfield,
         queryMode:qmode,
         typeAhead:true,
         maxHeight:mh,
         forceSelection:true,
         valueField:vfield,
         value:value
    });

    combox.parent = parent;

    return combox;
}

/************************************************************************************
 *	file select handler
 ************************************************************************************/
/**
 *	file button handler
 */
function on_file_select()
{
    qt_html.file_select( this.id );
}

/**
 *	callback function for file selecting
 *
 *	@id			[in] the id of component that call "qt_html.file_select"
 *	@path		[in] the file that being selected
 */
function callback_file_select( id, path )
{
    var button_cmp	= Ext.getCmp( id );

    if ( undefined !== button_cmp.file_select )
        button_cmp.file_select( path );
}
